package ar.com.cubika.trainees.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import ar.com.cubika.trainees.bean.transportes.Ruta;

public class UrlDAO extends AbstractMySQLDAO {

	// Singleton
	private static UrlDAO instance = new UrlDAO();

	private UrlDAO() {
	}

	public static UrlDAO getInstance() {
		return instance;
	}

	public void putUrls(List<String> urls, int id) {

		

		try {

			Statement stmt = getNewStatement();

			for(String url:urls){
				
				stmt.executeUpdate("INSERT INTO URLRUTA VALUES("+id+",'"+url+"')");
			}
			
			stmt.close();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	
	
	public List<String> getRutas(int id){
		
		List<String> rutas = new ArrayList<String>();
		
 		try {
 			
			Statement stmt = getNewStatement();
			String queryLink = "SELECT * FROM URLRUTA WHERE RUTA_ID ="+id+";";
			ResultSet rs = stmt.executeQuery(queryLink);
			
			while(rs.next()){
				
				String url = rs.getString("LINK");
				rutas.add(url);
			}
			
			stmt.close();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return rutas;
		
		
	}

	

	public Ruta deleteUrls(int id) {

		try {
			Statement stmt1 = getNewStatement();

			String query = "DELETE FROM URLRUTA WHERE RUTA_ID ='" + id + "';";

			stmt1.executeUpdate(query);

			stmt1.close();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
